<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>


  <script type="text/javascript">

      $(function(){
          $("#userdatagrid").datagrid({
              url:'${pageContext.request.contextPath}/user/findAll',
              pagination:true,
              method:'get',
              fit:true,
              pageSize:5,
              pageList:[5,10,15,20,25],
              fitColumns:true,
              striped:true,
              remoteSort:false,
              checkOnSelect:false,
              singleSelect:true,
              toolbar:'#usertoolbar',
              onLoadSuccess:function(){
                  $(".btn").linkbutton({
                      plain:true
                  })
              },
              columns:[[
                  {title:'用户id',field:'id',align:'center',width:260 },
                  {title:'姓名',field:'username',align:'center',width:150,sortable:true},
                  {title:'手机号',field:'tel',align:'center',width:150},
                  {title:'状态',field:'status',align:'center',width:150},
                  {title:'性别',field:'sex',align:'center',width:150,formatter:function(index,row,value){
                      if(value==0){
                          return "男"
                      }else{
                          return "女"
                      }
                      }},
                  {title:'操作',field:'options',width:300,formatter:function(index,row,value){
                      return "<a href='javascript:;' onclick='freezeUser("+JSON.stringify(row)+")' class='btn' data-options=\"iconCls:'icon-edit',\">冻结/解冻</a>"+
                          "<a href='javascript:;' onclick=\"openDetails('"+row.id+"')\" class='btn' data-options=\"iconCls:'icon-edit'\">查看详情</a>"

                      }}
              ]]
          })

      });

    //打开用户详细信息面板
    function openDetails(id){
        $("#detailsDialog").dialog({
            width:450,
            height:450,
            title:'员工详细信息',
            iconCls:'icon-man',
            href:'${pageContext.request.contextPath}/back/user/details.jsp?id='+id,
            buttons:[{
                text:'关闭',
                iconCls:'icon-remove',
                handler:function(){
                    $("#detailsDialog").dialog('close');
                }
            }],

        })
    }

    //模糊查询
    function findByLike(value,name){
        $("#userdatagrid").datagrid({
            url:'${pageContext.request.contextPath}/back/user/user.json/?param1='+name+'&param2='+value
        })
    }

    function freezeUser(row){
        if(row.status==0){
            $.messager.confirm('确认','您确认想要冻结吗？',function(r){
                if(r){
                    $.post("${pageContext.request.contextPath}/user/update",{"id":row.id,"status":1},function(){
                        $("#userdatagrid").datagrid("reload")
                    })
                }
            });
        }else{
            $.messager.confirm('确认','您确认想要解冻吗？',function(r){
                if(r){
                    $.post("${pageContext.request.contextPath}/user/update",{"id":row.id,"status":0},function(){
                        $("#userdatagrid").datagrid("reload")
                    })
                }
            });
        }
    }
  </script>

<table id="userdatagrid" ></table>
<div id="usertoolbar">
 </a>
  <input class="easyui-searchbox" data-options="prompt:'请输入',menu:'#mm',width:180,searcher:findByLike" >
</div>
<div id="mm">

  <div data-options="iconCls:'icon-man',name:'name'">姓名</div>
  <div data-options="iconCls:'icon-man',name:'status'">状态</div>

</div>
<div id="detailsDialog"></div>

